package business.global.pk.tdk;

import business.global.club.Club;
import business.global.club.ClubMgr;
import business.global.room.base.AbsBaseRoom;
import business.global.room.base.AbsRoomPos;
import cenum.RoomTypeEnum;
import com.ddm.server.common.utils.CommMath;
import jsproto.c2s.cclass.club.Club_define;

import java.util.Objects;

public class TDKRoomPos extends AbsRoomPos {
    /**
     * 赢场数
     */
    private int winCount = 0;
    /**
     * 输场数
     */
    private int loseCount = 0;
    /**
     * 接锅次数
     */
    private int jieGuoCount = 0;

    public TDKRoomPos(int posID, AbsBaseRoom room) {
        super(posID, room);
    }

    public TDKRoomPos(int posID, boolean isVisitor, AbsBaseRoom room) {
        super(posID, isVisitor, room);
    }

    @Override
    public AbsRoomPos getNewPos(){
        return new TDKRoomPos(this.getPosID(), this.isVisitor(), this.getRoom());
    }

    /**
     * 设置赢输平
     *
     * @param point
     */
    public void setCount(int point) {
        if (point > 0) {
            this.winCount += 1;
        } else {
            this.loseCount += 1;
        }
    }

    public int getWinCount() {
        return winCount;
    }

    public int getLoseCount() {
        return loseCount;
    }


    public int getJieGuoCount() {
        return jieGuoCount;
    }

    public void addJieGuoCount() {
        this.jieGuoCount++;
    }


    /**
     * 自动解散
     *
     * @param autoDismissValue 最低值
     * @return
     */
    @Override
    public boolean isAutoDismiss(double autoDismissValue) {
        if (RoomTypeEnum.UNION.equals(this.getRoom().getRoomTypeEnum())) {
            //中至的圈主不受自动解散限制
            if(Objects.nonNull(this.getClubMemberBO())){
                Club club= ClubMgr.getInstance().getClubListMgr().findClub(this.getClubMemberBO().getClubID());
                if(Objects.nonNull(club)){
                    if(club.isZhongZhiClub()&&this.getClubMemberBO().getIsminister()== Club_define.Club_MINISTER.Club_MINISTER_CREATER.value()){
                        return false;
                    }
                }
            }
            int defen = ((TDKRoom)this.getRoom()).getRoomCfg().getDifen();
            int dizhu = TDKdefine.TDK_DIFEN_TYPE.getFirstChipSet(defen, ((TDKRoomSet)this.getRoom().getCurSet()).getLanguoBeishu());
            return this.getRoomSportsPointValue() <= CommMath.FormatDouble(autoDismissValue) || this.getRoomSportsPointValue() <= dizhu;
        }
        return false;
    }

}
